#ifndef __GAME_DEBUG_UI_H
#define __GAME_DEBUG_UI_H
#include "game_platform.h"
#include "game_config.h"
struct debug_state;
struct debug_variable_link;
struct debug_tree;
struct debug_element;

enum debug_interaction_type {
    DebugInteraction_None,
    DebugInteraction_NOP,
    DebugInteraction_AutoModifyVariable,
    DebugInteraction_DragValue,
    DebugInteraction_ToggleValue,
    DebugInteraction_TearValue,
    DebugInteraction_Resize,
    DebugInteraction_Move,
    DebugInteraction_ToggleExpansion,
    DebugInteraction_Select,
    DebugInteraction_SetElementType,
    DebugInteraction_SetUInt32,
    DebugInteraction_SetPointer,
};
struct debug_interaction {
    debug_id ID;
    debug_interaction_type Type;
    void* Target;
    union {
        void* Pointer;
        uint32 UInt32;
        void* Generic;
        debug_type DebugType;
        debug_tree* Tree;
        debug_variable_link* Link;
        v2* P;
        debug_element* Element;
    };
};

struct layout {
    v2 MouseP;
    v2 BaseCorner;
    v2 At;
    int Depth;
    real32 LineAdvance;
    real32 NextYDelta;
    real32 SpacingY;
    real32 SpacingX;
    uint32 NoLineFeed;
    debug_state* DebugState;
    bool32 LineInitialized;
};

struct layout_element {
    layout* Layout;
    v2* Dim;
    v2* Size;
    debug_interaction Interaction;
    rectangle2 Bounds;
};
struct tooltip_buffer {
    uintptr_t Size;
    char* Data;
};
layout_element BeginElementRectangle(layout* Layout, v2* Dim);
// void MakeElementSizable(layout_element* Element);
inline void MakeElementSizable(layout_element* Element) { Element->Size = Element->Dim; }
void DefaultInteraction(layout_element* Element, debug_interaction Interaction);
void EndElement(layout_element* Element);
layout BeginLayout(debug_state* DebugState, v2 MouseP, v2 UpperLeftCorner);
void EndLayout(layout* Layout);

v2 BasicTextElement(layout* Layout, const char* Text, debug_interaction ItemInteraction,
                    v4 ItemColor = {1, 1, 1, 1}, v4 HotColor = v4{1, 1, 1, 1}, real32 Border = 0.0f,
                    v4 BackdropColor = v4{0, 0, 0, 0});

void BeginRow(layout* Layout);

void ActionButton(layout* Layout, const char* Name, debug_interaction Interaction);
void BooleanButton(layout* Layout, const char* Name, bool32 Highlight,
                   debug_interaction Interaction);
void EndRow(layout* Layout);
real32 GetLineAdvance(debug_state* DebugState);
real32 GetBaseLine(debug_state* DebugState);
void Label(layout* Layout, const char* Name);
tooltip_buffer AddTooltip(debug_state* DebugState);
void DrawTooltips(debug_state* DebugState);
#endif